{{extend './base.html'}}
{{block 'title'}}
账号设置
{{/block}}
{{block 'style'}}
<style>
    .list-group-flush li a {
        text-decoration: none;
        color: #4a4a4a;
    }

    .list-group-flush li.li-active a {
        color: #1e7e34;
    }

    #submit {
        width: 100%;
    }

    .row-wrapper {
        margin-top: 20px;
    }
</style>
{{/block}}
{{block 'content'}}
<div class="container">
    <div class="row row-wrapper">
        <div class="col-md-3 col-sm-12">
            <div class="card">
                <div class="card-header">
                    用户设置
                </div>
                <ul class="list-group list-group-flush">
                    <li class="list-group-item">
                        <a href="/user/center">
                            基本信息
                        </a>
                    </li>
                    <li class="list-group-item li-active">
                        <a href="/user/setting">
                            密码修改
                        </a>
                    </li>
                    <li class="list-group-item">
                        <a href="/user/blog">
                            文章管理
                        </a>
                    </li>
                    <li class="list-group-item">
                        <a href="/user/blog/edit">文章编辑</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="col-md-6 col-sm-12">
            <form>
                <div class="form-group">
                    <label>原密码</label>
                    <input type="password" class="form-control" placeholder="请输入原密码" name="old_password">
                </div>
                <div class="form-group">
                    <label>新密码</label>
                    <input type="password" class="form-control" placeholder="请输入新密码" name="new_password">
                </div>
                <div class="form-group">
                    <label>确认新密码</label>
                    <input type="password" class="form-control" placeholder="请输入新密码" name="new_password1">
                </div>
                <button type="button" class="btn btn-primary" id="submit">提交</button>
            </form>
        </div>
    </div>
</div>
{{/block}}
{{block 'js'}}
<script type="text/javascript">
    $('#submit').click(function () {
        const old_password = $('input[name="old_password"]').val();
        const new_password = $('input[name="new_password"]').val();
        const new_password1 = $('input[name="new_password1"]').val();
        if (new_password === '' || new_password1 === '' || old_password === '') {
            cocoMessage.warning("密码必填");
        } else {
            $.ajax({
                url: '/user/change_pwd',
                type: 'POST',
                data: {old_password, new_password, new_password1},
                success: function (res) {
                    if (res.err_code === 0) {
                        ccocoMessage.success("密码修改成功");
                    } else {
                        cocoMessage.warning(res.msg);
                    }
                }
            })
        }
    })
</script>
{{/block}}
